import service from '@/axios/index.js'

import { getCurrentDate } from '@/tools/index.js'


// 导流广告
export const fetchAdvert = () => {
  return service.get('/bannerData.json')
}

// 根据用户经纬度查询城市
export const fetchCityByLatLng = (latitude, longitude) => {
  return service.get(`/city/latlng?lat=${latitude}&lng=${longitude}`)
}

// 查询城市列表
export const fetchCitiesList = () => {
  return service.get('/cities.json')
}

// 最受好评电影
export const fetchTopRatedMovies = () => {
  return service.get('/index/topRatedMovies')
}

// 热映电影
export const fetchHotMovies = (cityId) => {
  return service.get(`/index/movieOnInfoList?ci=${cityId}`)
}

// 更多热映
export const fetchMoreHotMovies = (movieIds) => {
  return service.get(`/index/moreComingList?movieIds=${movieIds}`)
}

//电影院信息
export const fetchCinemas = (cityId) => {
  return service.get(`/index/filterCinemas?ci=${cityId}`)
}

//电影院列表
export const fetchCinemasList = (
  offset = 0,
  limit = 10,
  districtId = -1,
  areaId = -1,
  lineId = -1,
  stationId = -1,
  updateShowDay = true,
  hallType = -1,
  brandId = -1,
  serviceId = -1,
  cityId = 94, /* 默认海口 */
  lat = 0,
  lng = 0,
) => {
  return service.get(
    `/index/moreCinemas?day=${getCurrentDate()}&offset=${offset}&limit=${limit}&districtId=${districtId}&areaId=${areaId}&lineId=${lineId}&stationId=${stationId}&updateShowDay=${updateShowDay}&hallType=${hallType}&brandId=${brandId}&serviceId=${serviceId}&cityId=${cityId}&lat=${lat}&lng=${lng}`,
  )
}

//近期最受期待列表
export const fetchTopExpectedMovies = (cityId, limit, offset) => {
  return service.get(`/index/mostExpected?ci=${cityId}&limit=${limit}&offset=${offset}`)
}

//待映列表
export const fetchComingSoonMovies = (cityId, limit) => {
  return service.get(`/index/comingList?ci=${cityId}&limit=${limit}`)
}

//更多待映电影列表
export const fetchMoreComingSoonMovies = (cityId, limit, movieIds) => {
  return service.get(`/index/moreComingList?ci=${cityId}&limit=${limit}&movieIds=${movieIds}`)
}


//经典电影
export const fetchClassicMovies = (sortId, showType, limit, offset) => {
  return service.get(`/index/moreClassicList?sortId=${sortId}&showType=${showType}&limit=${limit}&offset=${offset}`)
}


// 搜索建议
export const fetchSearchSuggestions = (kw, cityId, stype = -1) => {
  return service.get(`/search/suggest?kw=${kw}&cityId=${cityId}&stype=${stype}`)
}

//电影/电视剧/综艺  影院  搜索
export const fetchSearchMoviesOrCinemas = (type, keyword, cityId, offset, limit = 20) => {

  return service.get(`/search/${type}?keyword=${keyword}&ci=${cityId}&offset=${offset}&limit=${limit}`)

}

// 电影院详情
export const fetchCinemaDetail = (cinemaId) => {
  return service.get(`/cinema/detail?cinemaId=${cinemaId}`)
}


// 当前影院上映电影排班表
export const fetchSchedule = (cinemaId, cityId, channelId = 4) => {
  return service.get(`/cinema/shows?cinemaId=${cinemaId}&ci=${cityId}&channelId=${channelId}`)
}

//  影院超值套餐
export const fetchCinemaPackages = () => {
  return service.get('/cinema/queryDealList.json')
}


// 影片详情
export const fetchMovieDetail = (movieId, cityId, channelId = 4) => {
  return service.get(`/movie/detail?movieId=${movieId}&cityId=${cityId}&channelId=${channelId}`)
}


// 影片介绍 (购票页面)
export const fetchMovieIntro = (movieId, cityId,) => {
  return service.get(`/movie/detail?movieId=${movieId}&cityId=${cityId}`)
}


//电影上映日期
export const fetchMovieShowDays = (movieId, cityId) => {
  return service.get(`/movie/showdays?movieId=${movieId}&cityId=${cityId}`)
}


//影片上映影院筛选条件
export const fetchMovieCinemaFilter = (movieId, cityId, showDate) => {
  return service.get(`/movie/select/items?movieid=${movieId}&cityId=${cityId}&showDate=${showDate}`)
}


// 影片上映影院筛选结果列表
export const fetchMovieCinemaListByFilter = (offset, limit, showDate, movieId, sort, cityId, lat, lng, districtId, lineId, areaId, stationId, brandIds, serviceIds, hallTypeIds, languageIds, dimIds) => {
  const params = {
    offset,
    limit,
    showDate,
    movieId,
    sort,
    cityId,
    lat,
    lng,
    districtId,
    lineId,
    areaId,
    stationId,
    brandIds: JSON.stringify(brandIds),
    serviceIds: JSON.stringify(serviceIds),
    hallTypeIds: JSON.stringify(hallTypeIds),
    languageIds: JSON.stringify(languageIds),
    dimIds: JSON.stringify(dimIds),
  };

  const queryString = Object.keys(params)
    .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
    .join('&');

  return service.get(`/movie/select/cinemas?${queryString}`);
}



// 视频
// offset 分页偏移 10/15的倍数
// feedChannelId 0推荐、1067226预告片、1331498热片解读、1074953说电影、1307354娱乐、
export const fetchVideo = (offset, feedChannelId) => {

  return service.get(`/video/${offset}?feedChannelId=${feedChannelId}`)

}



// 小视频
// offset 分页偏移 10的倍数
export const fetchClip = (offset) => {
  return service.get(`/video/short/${offset}`)
}
